Release 10.1A: OpenEdge Data Management:
SQL Development
How OpenEdge SQL interacts with Java
OpenEdge SQL stored procedures allow the use of standard Java programming constructs along with standard SQL statements. To do this, the OpenEdge SQL Engine interacts with Java in the following ways:
- When you create a stored procedure, the SQL engine processes the Java code, submits it to the Java compiler, receives the compiled result, and stores the result in the database.
- When an application calls a stored procedure, the SQL engine interacts with the Java Virtual Machine (JVM) to execute the stored procedure and receive any result.
Creating stored procedures
The Java source text that makes up the body of a stored procedure is not a complete Java program, but a program fragment or snippet that the OpenEdge SQL Engine converts into a complete Java class when it processes a
CREATE PROCEDUREstatement. Creating a stored procedure involves the following steps:
- A client application or tool issues a
CREATE PROCEDUREstatement that contains the Java source text.- The OpenEdge SQL Engine adds code to the Java snippet to create a complete Java class and submits the combined code to the Java compiler.
- Presuming there are no compilation errors, the Java compiler returns compiled bytecode back to the OpenEdge SQL Engine. If there are compilation errors, the OpenEdge SQL Engine passes the first error message generated by the compiler back to the application or tool that issued the
CREATE PROCEDUREstatement.- The OpenEdge SQL Engine stores both the Java source text and the bytecode form of the procedure in the database.
Figure 9–1 illustrates the general steps for creating a Java stored procedure.
Figure 9–1: Creating stored procedures
![]()
Calling stored procedures
Once a stored procedure is created and stored in the database, any application or other stored procedure can execute it. You can call stored procedures from either ODBC applications or JDBC applications.
Example 9–1 shows an excerpt from an ODBC application that calls a stored procedure (
order_parts) using the ODBC syntax {callprocedure_name ( param ) }.
A stored procedure executes using the following process:
- The application calls the stored procedure through its native calling mechanism. The previous example uses the ODBC call escape sequence.
- The OpenEdge SQL retrieves the compiled bytecode form of the procedure and submits it to the Java Virtual Machine for execution.
- For every SQL statement in the procedure, the Java Virtual Machine calls OpenEdge SQL.
- OpenEdge SQL manages the interaction of the stored procedure with the database and execution of the SQL statements, and returns any result to the Java Virtual Machine.
- The Java Virtual Machine returns result (output parameters and result sets) of the procedure to OpenEdge SQL, which in turn passes them to the calling application.
Figure 9–2 illustrates the steps in executing a stored procedure.
Figure 9–2: Executing stored procedures
![]()
Using stored procedures
Stored procedures extend the SQL capabilities of a database by adding control through Java program constructs that enforce business rules and perform administrative tasks.
Stored procedures can take advantage of the power of Java programming features. Stored procedures can:
OpenEdge SQL supports SQL statements in Java through several classes. See OpenEdge Data Management: SQL Reference for more information.
Table 9–1 summarizes the functionality of these OpenEdge SQL-supplied classes.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |